/**
 * 权限相关的数据
 * Created by gcc on 2017/9/29.
 */

import Vue from "vue";
import  { Tooltip } from 'view-design'

// 页码相关
let page = {
  total: 1,
  startIndex: 0,
  stepNumber: 40,
  currentPage: 1
};

let searchInfoPage ={
  total: 1,
  startIndex: 0,
  stepNumber: 40,
  currentPage: 1
};

//页面状态相关
let status = {
  //显示order的 modal
  modalOrder: {
    isShow: false,
  },
  //显示cart的 modal
  modalCart: {
    isShow: false,
  },
  //显示address的 modal
  modalAddress: {
    isShow: false,
  },
  //显示record的 modal
  modalRecord: {
    isShow: false,
  },
  //查看图片
  modalImage: {
    isShow: false,
    url: ''
  },
  modalUserInfo:{
    isShow: false
  },
  //订单详情
  modalOrderDetail:{
    isShow:false
  },
  modalUserRecord: {
    info:{
      productCode:"",
      productColor:"",
      productSize:""
    },
    isShow: false,
  },
  noteModal:{
    isShow:false,
    isLoading:false,
    title:"添加用户备注"
  },
  activeModal:{
    isShow:false,
    isLoading:false,
    title:"激活用户"
  },
  countryModal:{
    isShow:false,
    isLoading:false,
    title:"选择国家"
  },
  modalProxySites: {
    isShow: false,
  }
};

// 和网络交互相关的参数
let params = {
  //搜索条件
  contactEmail: '',
  firstName: '',
  startEndDate: [],
  orderBy: '',
  selectedUsers:[],
  showOrder: {
    userId: '',
    pageNum: 1,
    pageSize: 40,
    total: 1
  },
  showCart: {
    userId: ''
  },
  showAddress: {
    userId: ''
  },
  showRecord: {
    userId: '',
    pageNum: 1,
    pageSize: 20,
    total: 1
  },
  showUserInfo:{
    firstName:'',
    lastName:'',
    thirdParty:'',
    state:'',
    country:'',
    phone:'',
    email:'',
    isPushMessage:'',
    isAdEmail:'',
    facebook:'',
    whatsapp:'',
    twitter:'',
    instagram:'',
    source:'',
    inviteCode:'',
    useContent:'',
    userId:'',
    tabList:[],
  },
  userNoteList:[]

};

// 页面的数据源
let data = {
  userList: [],
  loginTypeDict: [],
  orderItemDict: [],
  orderList: [],
  tabList:[],
  orderDetail: {
    actualPayment: "",
    addressId: "",
    checkoutTime: "",
    clientId: "",
    country: "",
    countryName: "",
    createtime: "",
    deliveryMethod: "",
    deviceType: "",
    discounts: [],
    id: "",
    itemCount: "",
    // items: [],
    note: "",
    orderPostage: {},
    originalPrice: "",
    packages: [],
    payWay: "",
    payWayName: "",
    payer: "",
    paymentAccount: "",
    paymentSerialNumber: "",
    postage: "",
    productCount: "",
    receiverInfo: {},
    serialNumber: "",
    state: "",
    stateName: "",
    userId: "",
    userName: "",
    weight: "",
    logisticsInvoiceType:0,
    logisticsInvoiceAmount:0
  },
  selectRecord: [],
  cartList: [],
  addressList: [],
  recordList: [],
  cartWeightCount: '',
  cartPriceCount: '',

  dateRange: {
    disabledDate (date) {
      return date && date.valueOf() > Date.now();
    },
    shortcuts: [
      {
        text: '清空时间',
        value () {
          return [];
        }
      },
      {
        text: '最近一周',
        value () {
          const end = new Date();
          const start = new Date();
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
          return [start, end];
        }
      },
      {
        text: '最近一个月',
        value () {
          const end = new Date();
          const start = new Date();
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
          return [start, end];
        }
      },
      {
        text: '最近三个月',
        value () {
          const end = new Date();
          const start = new Date();
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
          return [start, end];
        }
      }
    ]
  },

note:{
    name:'',
  content:''
},
  activeInfo:{
    userId:'',
    firstName:'',
    lastName:'',
    contactEmail:'',
    phoneCode:'',
    phone:'',
    facebook:'',
    instagram:'',
    useType:'',
    source:'',
    countryCode:'',
    inviteCode:'',
    isAdEmail:false,
    isPushMessage:false
  },
  proxySites: [],
};

  let tableCartTitles = function (self) {
    return [
      {
        title: '产品编码',
        key: 'productCode',
        align: 'center',
        render: (h, params) => {
          var productUrl = Vue.prototype.$tiyProductUrl(params.row.productCode);
          return h('div', [h('a', {
            attrs: {href: productUrl, target: '_blank'}
          }, params.row.productCode)]);
        }
      },
      {
        title: '产品图片',
        key: 'colorJson',
        align: 'center',
        render: (h, params) => {
          {
            var image = params.row.productImgUrl;
            let yunPath = Vue.prototype.$store.getters.imgPrefix;
            return h('div', [h('img', {
              attrs: {src: yunPath + image, height: 60},
              on: {
                click: () => {
                  status.modalImage.url = yunPath + image;
                  status.modalImage.isShow = true;
                }
              }
            }, image)
            ]);
          }
        }
      },
      {
        title: '色卡',
        key: 'color',
        align: 'center',
      },
      {
        title: '尺码规格',
        key: 'sizeName',
        align: 'center',
      },
      {
        title: '当前售价($)',
        align: 'center',
        key: 'price'
      },
      {
        title: '	数量',
        key: 'amount',
        align: 'center',
      },
      {
        title: '重量(g)',
        key: 'weight',
        align: 'center',
      },
      {
        title: '添加时间',
        key: 'createtime',
        align: 'center',
        width: 150,
        render: (h, params) => {
          return h('div', self.$tiyBJTime(params.row.createtime));
        }
      }
    ];
  };
  let tableAddressTitles=[
    {
      type: 'index',
      title: '#',
      width: 50
    },
    {
      title: '收货人',
      key: 'receiver',
      width: 100
    },
    {
      title: '电话',
      key: 'phone',
      width: 150
    },
    {
      title: '邮政编码',
      key: 'postcode',
      width: 100
    },
    {
      title: '国家',
      key: 'country',
      width: 120
    },
    {
      title: '地址',
      render: (h, params) => {
        return h('div', params.row.state + ' | ' + params.row.city + ' | ' + params.row.houseNumber);
      }
    }
   ];


  let  tableOrderDetail=function(self){
    return [
      {
        title: '产品编码',
        key: 'productCode',
        align: 'center',
      },
     {
        title: '色卡',
        key: 'color',
        align: 'center',
      },
      {
        title: '尺码',
        key: 'sizeName',
        align: 'center',
      },
      {
        title: '数量',
        key: 'amount',
        align: 'center',
      },
     {
        title: '折扣金额($)',
        key: "itemDiscount",
        align: 'center',
        render: (h, params) => {
          var discount = (params.row.actualPrice * params.row.amount - params.row.actualPayment).toFixed(3);
          if(discount <= 0){ //没有折扣时显示0，有折扣显示折扣值并作a链接
            return h('div', 0);
          } else {
            return h('div',discount);
          }
        }
      },

    {
        title: '订单项状态',
        key: 'state',
        align: 'center',
        width: 130,
        render: (h, params) => {
          return h('div', self.$store.getters.dictionaries.orderItemStateDict.filter(item => item.value === params.row.state)[0].name);
        }
      },
      {
        title: '订单操作记录',
        align: 'center',
        width: 120,
        render: (h, params) => {
          return h('Button',
            {
              on: {
                click: () => {
                  data.selectRecord.length = 0;
                  self.webItemRecord(params.row);
                }
              }
            }, '查看');
        }
      }
]
    }


let tableUserRecordDetail=[
  {
    type: 'index',
    title: '#',
    align: 'center',
    width: 60
  },
  {
    title: '操作后订单项状态',
    key: 'stateName',
  },
  {
    title: '操作人',
    key: 'operator',
    align: 'center',
    width: 120
  },
  {
    title: '操作时间',
    key: 'createtime',
    align: 'center',
    width: 150,
    render: (h, params) => {
      return h('div', self.$tiyBJTime(params.row.createtime));
    }
  }
];


export  default  {
  tPage: page,
  searchInfoPage: searchInfoPage,
  tStatus: status,
  tParams: params,
  orderItemTitles:tableOrderDetail,
  // cartTableTitles:tableCartTitles,
  addressTableTitles:tableAddressTitles,
  tableUserRecordDetail:tableUserRecordDetail,
  tData: data,
  tRole: {}
};
